package com.wuniutech.notebook

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.view.View
import android.widget.Button

class StartActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_start)
        val getAndroidIdBt = findViewById<Button>(R.id.get_android_id_bt)
        val androidId = DeviceUtils.getAndroidID()
        val user = UserManager.users.find { it.androidId == androidId }

        if (user != null) {
            val userLoginTime = System.currentTimeMillis() - user.startTime
            val useDay = userLoginTime / 1000 / 60 / 60 / 24
            val deadlineTime = user.deadline * 360
            if (useDay > deadlineTime) {
                ToastUtil.showLongToast("您的账号已过期，请联系管理员")
            } else {
                Handler().postDelayed({
                    startActivity(Intent(this, MainActivity::class.java))
                    finish()
                }, 2000)
            }
        } else {
            getAndroidIdBt.visibility = View.VISIBLE
        }
        getAndroidIdBt.setOnClickListener {
            val content = DeviceUtils.getAndroidID()
            DeviceUtils.copyTextToClipboard(this, "", content)
        }
    }
}